<?php
/**
* Add albums by scanning files on the server.
*/

if($album_folder = $_POST['album']['folder'])
{
	# Try to read the relative path FTP based uploads
	# Otherwise, just continue assuming that the user sent FULL PATH of the directory.
	
	$album_folder = str_replace('\\', '/', $album_folder);
	
	$ftp_directory = realpath(str_replace('\\', '/', FTPPATH_ALBUMS.'/'.$album_folder));
	if(is_dir($ftp_directory)) $album_folder = $ftp_directory;

	if(!is_dir($album_folder))
	{
		$messenger = new messenger('error', "Such album folder does not exist - <strong>{$album_folder}</strong>");
		stopper::url('albums-list.php');
	}
	
	$album_scanner = new scanner($album_folder);
	$album_scanner->patch_counter();
	
	# Set the original image size store location
	$albumsizes = new albumsizes();
	$albumsizes->add_album_size_originally_scanned($album_scanner->album_id, $album_folder, THUMBNAIL_ORIGINAL_SIZE_ID);
	
	# Assign all other default thumbnail sizes and their locations
	$albumsizes->assign_all_default_sizes($album_scanner->album_id);
	
	$messenger = new messenger('notice', "Album scanned: <strong>{$album_folder}</strong>. Manage sizes NOW!");
	
	stopper::url("albums-details.php?id={$album_scanner->album_id}&code=code#manage");
}

stopper::url('albums-list.php');
?>